package com.sudoku.register.action;

import java.util.HashMap;
import java.util.Map;

import com.common.utils.JavaBeanUtils;
import com.opensymphony.xwork2.ActionSupport;
import com.pojo.Sudokuer;
import com.sudoku.register.RegisterService;

@SuppressWarnings("serial")
public class RegisterAction extends ActionSupport {

	private String sudokuerName;
	private String password;
	private String nation;
	private int age;
	private int sudokuAge;
	private RegisterService registerService;
	private String res;
	
	public String getRes() {
		return res;
	}
	public void setRes(String res) {
		this.res = res;
	}
	public int getSudokuAge() {
		return sudokuAge;
	}
	public void setSudokuAge(int sudokuAge) {
		this.sudokuAge = sudokuAge;
	}
	public RegisterService getRegisterService() {
		return registerService;
	}
	public void setRegisterService(RegisterService registerService) {
		this.registerService = registerService;
	}
	public String getSudokuerName() {
		return sudokuerName;
	}
	public void setSudokuerName(String sudokuerName) {
		this.sudokuerName = sudokuerName;
	}
	public String getPassword() {
		return password;
	}
	public void setPassword(String password) {
		this.password = password;
	}
	public String getNation() {
		return nation;
	}
	public void setNation(String nation) {
		this.nation = nation;
	}
	public int getAge() {
		return age;
	}
	public void setAge(int age) {
		this.age = age;
	}
	
	public String hasSameName() {
		Map<String,String> temp = new HashMap<String,String>();
		if(registerService.findSameName(this.sudokuerName)!=0) {
			temp.put("count","1");
		}else {
			temp.put("count","0");
		}
		res = JavaBeanUtils.toJson(temp);
		return SUCCESS;
	}
	
	public String registerSudokuer() {
		Sudokuer su = new Sudokuer();
		JavaBeanUtils.copyProperties(su,this);
		registerService.insertRegister(su);
		return SUCCESS;
	}
}
